'use strict';

const Service = require('../core/base_service');

class FeedbackService extends Service {
  // 提交意见反馈
  async createFeedback (payload) {
    let res
    try {
      res = await this.ctx.model.Feedback.create(payload)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }

  // 获取全部反馈
  async getFeedback (params) {
    let res
    try {
      res = await this.ctx.model.Feedback.find(params)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }

  // 获取全部反馈
  async getFeedbackmohu (params) {
    let res
    try {
      res = await this.ctx.model.Feedback.find({ mobile: { $regex: params.mobile } })
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }

  // 修改
  async updateFeedback (payload) {
    let res
    try {
      res = await this.ctx.model.Feedback.findByIdAndUpdate(payload._id, payload)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }

  // 删除
  async deleteFeedback (payload) {
    let res
    try {
      res = await this.ctx.model.Feedback.findByIdAndRemove(payload._id)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }
}

module.exports = FeedbackService;
